public class Location {
	
	private static boolean relocate = false;
	
	static Object[] unownedOptions = { "Buy", "Don't Buy" };
	static Object[] ownedOptions = { "Pay Rent" };
	static Object[] okayOption = { "Okay" };
	
	public static boolean getRelocate() {
		
		return relocate;
	}

	public static void setRelocate(boolean relocate) {
		
		Location.relocate = relocate;
	}

	public static Player setStartingLocation(Player a, int x) {
		
		switch(x) {
		
			case 0:
				a.setXLocation(763); 
				a.setYLocation(724);
				break;
			case 1:
				a.setXLocation(744); 
				a.setYLocation(724);
				break;
			case 2:
				a.setXLocation(725); 
				a.setYLocation(724);
				break;
			case 3:
				a.setXLocation(763); 
				a.setYLocation(743);
				break;
			case 4:
				a.setXLocation(744); 
				a.setYLocation(743);
				break;
			case 5:
				a.setXLocation(725); 
				a.setYLocation(743);
				break;
			case 6:
				a.setXLocation(763); 
				a.setYLocation(762);
				break;
			case 7:
				a.setXLocation(744); 
				a.setYLocation(762);
				break;
		}
		
		return a;
	}
	
	public static Player useLot(Player a, int x) {
		
		if (LotTiles.values()[x].getOwner() != null) {
			
			Player owner = LotTiles.values()[x].getOwner();
			String header = owner.getName() + "'s Property - " + LotTiles.values()[x].getLotName();
			
			if (LotTiles.values()[x].getMortgaged() == true) {
				
				header = owner.getName() + "'s Property - " + LotTiles.values()[x].getLotName() + " (Mortgaged)";
			}
			
			if (LotTiles.values()[x].getOwner() == a || LotTiles.values()[x].getMortgaged() == true) {
				
				BoardGUI.dynamicDialogBox(okayOption, LotTiles.values()[x].getTileURL(), header);
			}
			
			else {
			
				BoardGUI.dynamicDialogBox(ownedOptions, LotTiles.values()[x].getTileURL(), header);
				a = Pay.payLotRent(a, LotTiles.values()[x].ordinal());
			}
		}
		
		else {
			
			int y = BoardGUI.dynamicDialogBox(unownedOptions, LotTiles.values()[x].getTileURL(), LotTiles.values()[x].getLotName());
		
			if (y == 0) {
				
				a = Buy.buyLot(a, LotTiles.values()[x].ordinal());
			}
		}
		
		return a;
	}
	
	public static Player useTrain(Player a, int x) {
		
		if (TrainTiles.values()[x].getOwner() != null) {
			
			Player owner = TrainTiles.values()[x].getOwner();
			String header = owner.getName() + "'s Property - " + TrainTiles.values()[x].getTrainName();
			
			if (TrainTiles.values()[x].getMortgaged() == true) {
				
				header = owner.getName() + "'s Property - " + TrainTiles.values()[x].getTrainName() + " (Mortgaged)";
			}
			
			if (TrainTiles.values()[x].getOwner() == a || TrainTiles.values()[x].getMortgaged() == true) {
				
				BoardGUI.dynamicDialogBox(okayOption, TrainTiles.values()[x].getTileURL(), header);
			}
			
			else {
			
				BoardGUI.dynamicDialogBox(ownedOptions, TrainTiles.values()[x].getTileURL(), header);
				a = Pay.payTrainRent(a, TrainTiles.values()[x].ordinal());
			}
		}
		
		else {
			
			int y = BoardGUI.dynamicDialogBox(unownedOptions, TrainTiles.values()[x].getTileURL(), TrainTiles.values()[x].getTrainName());
		
			if (y == 0) {
				
				a = Buy.buyTrain(a, TrainTiles.values()[x].ordinal());
			}
		}
		
		return a;
	}
	
	public static Player useUtility(Player a, int x) {
		
		if (UtilitiesTiles.values()[x].getOwner() != null) {
			
			Player owner = UtilitiesTiles.values()[x].getOwner();
			String header = owner.getName() + "'s Property - " + UtilitiesTiles.values()[x].getUtilityName();
			
			if (LotTiles.values()[x].getMortgaged() == true) {
				
				header = owner.getName() + "'s Property - " + UtilitiesTiles.values()[x].getUtilityName() + " (Mortgaged)";
			}
			
			if (UtilitiesTiles.values()[x].getOwner() == a || UtilitiesTiles.values()[x].getMortgaged() == true) {
				
				BoardGUI.dynamicDialogBox(okayOption, UtilitiesTiles.values()[x].getTileURL(), header);
			}
			
			else {
			
				BoardGUI.dynamicDialogBox(ownedOptions, UtilitiesTiles.values()[x].getTileURL(), header);
				a = Pay.payUtilitiesRent(a, UtilitiesTiles.values()[x].ordinal());
			}
		}
		
		else {
			
			int y = BoardGUI.dynamicDialogBox(unownedOptions, UtilitiesTiles.values()[x].getTileURL(), UtilitiesTiles.values()[x].getUtilityName());
		
			if (y == 0) {
				
				a = Buy.buyUtility(a, UtilitiesTiles.values()[x].ordinal());
			}
		}
		
		return a;
	}
	
	public static Player useChance(Player a) {
		
		BoardGUI.dynamicDialogBox(okayOption, Chance.getChanceURL(16), "Chance");
		Chance.drawCard();
		
		BoardGUI.dynamicDialogBox(okayOption, Chance.getChanceURL(Chance.getPick()), "Chance");
		a = Chance.implementCard(a);
		
		return a;
	}
	
	public static Player determineLocation(Player a) {
		
		switch (a.getCurrLoc()) {
		
			case 0:
				break;
			case 1:
				a = Location.useLot(a, LotTiles.OKR.ordinal());
				break;
			case 2:
				//COMMUNTIY CHEST
				break;
			case 3:
				a = Location.useLot(a, LotTiles.WR.ordinal());
				break;
			case 4:
				BoardGUI.dynamicDialogBox(okayOption, TaxTiles.getImageURL(0), TaxTiles.getName(0));
				a = TaxTiles.payIncomeTax(a);
				break;
			case 5:
				a = Location.useTrain(a, TrainTiles.KCS.ordinal());
				break;
			case 6:
				a = Location.useLot(a, LotTiles.TAI.ordinal());
				break;
			case 7:
				a = Location.useChance(a);
				break;
			case 8:
				a = Location.useLot(a, LotTiles.ER.ordinal());
				break;
			case 9:
				a = Location.useLot(a, LotTiles.PR.ordinal());
				break;
			case 10:
				if (a.getJail() == false) {
				
					BoardGUI.dynamicDialogBox(okayOption, SpecialTiles.getImageURL(1), SpecialTiles.getName(1));
				}
				break;
			case 11:
				a = Location.useLot(a, LotTiles.PM.ordinal());
				break;
			case 12:
				a = Location.useUtility(a, UtilitiesTiles.EC.ordinal());
				break;
			case 13:
				a = Location.useLot(a, LotTiles.W.ordinal());
				break;
			case 14:
				a = Location.useLot(a, LotTiles.NA.ordinal());
				break;
			case 15:
				a = Location.useTrain(a, TrainTiles.MS.ordinal());
				break;
			case 16:
				a = Location.useLot(a, LotTiles.BW.ordinal());
				break;
			case 17:
				//COMMUNITY CHEST
				break;
			case 18:
				a = Location.useLot(a, LotTiles.MS.ordinal());
				break;
			case 19:
				a = Location.useLot(a, LotTiles.VS.ordinal());
				break;
			case 20:
				BoardGUI.dynamicDialogBox(okayOption, SpecialTiles.getImageURL(2), SpecialTiles.getName(2));
				break;
			case 21:
				a = Location.useLot(a, LotTiles.S.ordinal());
				break;
			case 22:
				a = Location.useChance(a);
				break;
			case 23:
				a = Location.useLot(a, LotTiles.FS.ordinal());
				break;
			case 24:
				a = Location.useLot(a, LotTiles.TS.ordinal());
				break;
			case 25:
				a = Location.useTrain(a, TrainTiles.FSS.ordinal());
				break;
			case 26:
				a = Location.useLot(a, LotTiles.LS.ordinal());
				break;
			case 27:
				a = Location.useLot(a, LotTiles.CS.ordinal());
				break;
			case 28:
				a = Location.useUtility(a, UtilitiesTiles.WW.ordinal());
				break;
			case 29:
				a = Location.useLot(a, LotTiles.P.ordinal());
				break;
			case 30:
				BoardGUI.dynamicDialogBox(okayOption, SpecialTiles.getImageURL(3), SpecialTiles.getName(3));
				break;
			case 31:
				a = Location.useLot(a, LotTiles.RS.ordinal());
				break;
			case 32:
				a = Location.useLot(a, LotTiles.OS.ordinal());
				break;
			case 33:
				//COMMUNITY CHEST
				break;
			case 34:
				a = Location.useLot(a, LotTiles.BS.ordinal());
				break;
			case 35:
				a = Location.useTrain(a, TrainTiles.LSS.ordinal());
				break;
			case 36:
				a = Location.useChance(a);
				break;
			case 37:
				a = Location.useLot(a, LotTiles.PL.ordinal());
				break;
			case 38:
				BoardGUI.dynamicDialogBox(okayOption, TaxTiles.getImageURL(1), TaxTiles.getName(1));
				a = TaxTiles.paySuperTax(a);
				break;
			case 39:
				a = Location.useLot(a, LotTiles.M.ordinal());
				break;
		}
		
		return a;
	}
	
	public static int[] moveToken(Player player) {
		
		//tile 39 to Go
		if (player.getCurrLoc() == 39) {
			
			int[] z = { player.getXLocation(), player.getYLocation()+89 };
			return z;
		}
		
		//GO to tile 1
		else if (player.getCurrLoc() == 0) {
			
			int[] z = { player.getXLocation()-91, player.getYLocation() };
			return z;
		}
		
		//Between Go and Jail
		else if (player.getCurrLoc() < 9 && player.getCurrLoc() > 0) {
			
			int[] z = { player.getXLocation()-67, player.getYLocation() };
			return z;
		}

		//tile 9 to Jail
		else if (player.getCurrLoc() == 9) {
			
			int[] z = { player.getXLocation()-86, player.getYLocation() };
			return z;
		}
		
		//Jail to tile 11
		else if (player.getCurrLoc() == 10) {
			
			int[] z = { player.getXLocation(), player.getYLocation()-89 };
			return z;
		}
		
		//Between Jail and Free Parking
		else if (player.getCurrLoc() < 19 && player.getCurrLoc() > 10) {
			
			int[] z = { player.getXLocation(), player.getYLocation()-66 };
			return z;
		}
		
		//tile 19 to Free Parking
		else if (player.getCurrLoc() == 19) {
			
			int[] z = { player.getXLocation(), player.getYLocation()-89 };
			return z;
		}
		
		//Free Parking to tile 21
		else if (player.getCurrLoc() == 20) {
			
			int[] z = { player.getXLocation()+89, player.getYLocation() };
			return z;
		}
		
		//Between Free Parking and Go to Jail
		else if (player.getCurrLoc() < 29 && player.getCurrLoc() > 20) {
			
			int[] z = { player.getXLocation()+66, player.getYLocation() };
			return z;
		}
		
		//tile 29 to Go to Jail
		else if (player.getCurrLoc() == 29) {
			
			int[] z = { player.getXLocation()+91, player.getYLocation() };
			return z;
		}
		
		//Go to Jail to tile 31
		else if (player.getCurrLoc() == 30) {
			
			int[] z = { player.getXLocation(), player.getYLocation()+89 };
			return z;
		}
		
		//Go to Jail and Go
		else if (player.getCurrLoc() < 39 && player.getCurrLoc() > 30) {
			
			int[] z = { player.getXLocation(), player.getYLocation()+66 };
			return z;
		}
		
		else {
			int[] z = { player.getXLocation(), player.getYLocation() };
			return z;
		}
	}
	
	public static Player teleportLocation(Player a) {
		
		int[] z;
		
		for (int x = a.getCurrLoc(); x < a.getStop(); x++) {
			
			z = Location.moveToken(a);
			
			a.setXLocation(z[0]);
			a.setYLocation(z[1]);
						
			a = BoardGUI.setCurrLoc(a, x+1);
		}
		
		return a;
	}
}